import { Component } from "react";
import { Picker, Cell } from "@nutui/nutui-react-taro";
import styles from "./index.scss";

import Taro from "@tarojs/taro";
import { useState } from "react";
import Layout from "@/components/Layout";

import { useModel } from "@/store";

import { useEffect } from "react";
import {
  queryOutpAcctInfo,
  queryClinicChargePat,
  queryOutpPatBill,
} from "@/services/payment";
import { queryScheduleInfo, queryOutpReg } from "@/services/register";
import ListView from "@/components/ListView";
import { formatDate, calculateTime } from "@/utils/repeated";
import {ArrowRight} from '@nutui/icons-react-taro'

const options = [
  { value: 1, text: "全部", days: 10000 },
  { value: 2, text: "近一个月", days: 30 },
  { value: 3, text: "近三个月", days: 90 },
];

export default () => {
  const [visible, setVisible] = useState(false);
  const [pickerValue, setPickerValue] = useState(2);

  const { curPatientInfo } = useModel("patient");
  const changePicker = (list, option, columnIndex) => {
    console.log(columnIndex, option);
  };
  const confirmPicker = (list, values) => {
    console.log(list, values);
    setPickerValue(list[0].value);
  };
  // confirmPicker
  return (
    <Layout title="查询">
      <view className={styles.inquiryListWarp}>
        <view  className={styles.timeRangePicker} onClick={() => setVisible(!visible)}>
          <view>时间：</view>
          <view>
            {options?.filter((x) => x.value === pickerValue)[0]?.text}{" "}
          </view>
          <ArrowRight width={'12px'} style={{marginLeft:'4px'}} />
          <Picker
            visible={visible}
            defaultValue={[pickerValue]}
            options={options}
            onConfirm={(list, values) => confirmPicker(list, values)}
            onClose={() => setVisible(false)}
            onChange={changePicker}
          />
        </view>
        <ListView
          getList={queryOutpReg}
          isReverse={true}
          params={{
            // patientId:'01660255',
            patientId: curPatientInfo.patientId,
            // patientId: "01733667",
            startDate: calculateTime(
              -options?.filter((x) => x.value === pickerValue)[0]?.days
            ),
            endDate: calculateTime(7),
            pageSize: 9999,
            // pageNo: 1,

          }}
          row={(item, index) => (
            <view
              key={item.autoRcptNo}
              className={styles.inquiryCard}
              onClick={() => {


                // queryOutpPatBill({
                //   // patientId: curPatientInfo.patientId,
                //   regSerialNo: item.autoRcptNo,
                //   // patientId: "01733667",
                //   // 010624031314322314 010624031314322314
                //   //   queryNo: curPatientInfo.patientId,
                //   startDate: "1970-01-01",
                //   endDate: calculateTime(0),
                //   pageSize: 999,
                //   pageNo: 1,
                // }).then((res) => {
                //   if (res) {
                //     // setList(res);
                //   }
                // });
                Taro.navigateTo({
                  url: `/pages/inquiry/costDetails/index?autoRcptNo=${item.autoRcptNo}`,
                });
              }}
            >
              <view className={styles.content}>
                <view className={styles.text}>
                  就诊科室：{item.visitDept}
                </view>
                <view className={styles.text}>
                  就诊医生：{item.doctor}
                </view>
                <view className={styles.text}>就诊时间：{item.visitDate}</view>
              </view>
              <view className={styles.bottom}>
                <view className={styles.price}></view>
                {/* <view className={styles.price}>￥{item.totalCosts}</view> */}
                <view className={styles.action}> 查看详情{">"}</view>
              </view>
            </view>
          )}
        ></ListView>
      </view>
    </Layout>
  );
};
